-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fet/rest relation endpoints (fixes #790) #798
Conversation
…e. Not sure why I thought that.
…rting or updating data
First off, FYI I've written tentative documentation here: https://github.com/eventespresso/event-espresso-core/blob/FET/rest-relation-endpoints/docs/C--REST-API/ee4-rest-api-editing-relations.md Several items I'd like Feedback on
|
Behaviour wise, what benefit is there to having multiple rows for that relation? Although it may be possible I think functionally wise, any code implementing this data would have the expectation there is only one record per question_group/question record right? So imo it should only allow one record per relation. The other problem with allowing multiple records to get created is the side effect of how the join table data is represented in the
Again, functionally speaking, what action performed by client code would have the expectation there'd be multiple relation rows for each question group -> question record? In other words, should we even be getting into the state of having multiple records for these relations in the table? So, on the off chance there are somehow, I'm fine with DELETE removing all entries in the table for that particular relation.
You could have a
I think we'll have to be consistent with what the link in the schema is given for the relation (i.e. |
I want to be thrifty with adding more routes to the WP API index, as we've already got so many that we've had errors storing them in the WP options table (and generating them via the models on every REST API request is a significant time sink). So I'd rather stick with the existing routes, which are sometimes singular (eg kk, so to-do
|
…sume only one row in join entries, so why would they want to provide the where query parameter when removing a relation
I just want to highlight that this does block #790 from being complete as I need to wire things up there to work with the new endpoints and test appropriately. While I can merge this branch in, I'd be more comfortable with landing this in master first so I can avoid potential merge conflicts and this is baked a bit in master before releasing #790. |
I had heard we were asking Josh to do more of the triaging now, so passing to you Josh instead for assigning to someone for testing. (Please let me know if I should handle differently.) |
tested & ready for merge, pending unit test fixes. |
It seems there was some change to Travis that's causing that (I think Brent was basically reporting the same issue here: https://eventespresso.slack.com/archives/C04J554E8/p1545942570001900). |
…relation endpoints (#798) * add routes for adding and removing relations * add validateModel method for reduring duplicated code in child classes * use validateModel to make code more DRY * theoretically, rest relation updating endpoints have been added. Untested * first test and a few fixes * relation adding and removing endpoints are unit tested * phpcbf fixes * import classes during unit tests * ModelDataTranslator::prepareFieldvalueForJson doesnt need the timezone. Not sure why I thought that. * import more classes * if they provide invalid parameters have an error, just like when inserting or updating data * deletion is successful if no row was found * update test expectations * update documentation to mention new relation editing endpoints * added item to REST API changelog * ouops all these tests should remove relations so be named like that * removing relations does not accept any parameters. These endpoints assume only one row in join entries, so why would they want to provide the where query parameter when removing a relation * assert that we remove ALL relations when removing relations not just one * consider join table entries as duplicates based only on foreign keys * update tests to make sure we update relations instead of adding duplicates in join tables when adding a relation but a slightly different one already exists * update tests to make sure we update relations instead of adding duplicates in join tables when adding a relation but a slightly different one already exists * phpcbf fix * update documentation * remove the unnecessary success property and document it * fix fatal error when running tests on phpunit4.8 * fixed some documentation typos as brent suggested "
#875) <!-- Thanks for your pull request. Comments within these type of tags will be hidden and not show up when you submit your pull request --> <!-- Please answer the following questions in order to expediate acceptance --> ## Problem this Pull Request solves <!-- Please describe your changes in the context of the problem they solve --> Fixes an unreleased issue from #798 which caused primary attendee question groups to be disassociated with their event. See #873 This fixes it by, instead of only considering a join table row a duplicate based solely on its foreign keys, also take into account other columns (in the case of event-question-group, its `EQG_primary` value). This causes the primary question group relation to not get overwritten. **Note**: if you have an event on which you were reproducing #873, just switching to this branch and updating the event **won't** fix it. This just prevents the issue from occurring in the future for newly saved events. (IMO that's ok because this hasn't been released yet, so it's just us EE team who are inconvenienced- had it been released we'd want to retroactively fix those events) ## How has this been tested <!-- Please describe in detail how you tested your changes and how testing can be reproduced --> <!-- Include details of your testing environment, and tests ran to see how your changes affect other areas of code --> <!-- Include any notes about automated tests you've written for this pull request. Pull requests with automated tests are preferred. --> * [ ] 1. Set up an event that requires the Personal Information Group for Additional Attendees 2. Select 2 or more tickets, and submit TS form 3. You'll be redirected to SPCO step 1 4. See missing attendee 1 form ## Checklist * [ ] I have read the documentation relating to systems affected by this pull request, see https://github.com/eventespresso/event-espresso-core/tree/master/docs * [ ] User input is adequately validated and sanitized * [ ] all publicly displayed strings are internationalized (usually using `esc_html__()`, see https://codex.wordpress.org/I18n_for_WordPress_Developers) * [ ] My code is tested. * [ ] My code follows the Event Espresso code style. * [ ] My code has proper inline documentation. * [ ] My code accounts for when the site is in Maintenance Mode (MM2 especially disallows usage of models)
…f only using FKs to identify a duplicate, use all the columns (#875) <!-- Thanks for your pull request. Comments within these type of tags will be hidden and not show up when you submit your pull request --> <!-- Please answer the following questions in order to expediate acceptance --> ## Problem this Pull Request solves <!-- Please describe your changes in the context of the problem they solve --> Fixes an unreleased issue from #798 which caused primary attendee question groups to be disassociated with their event. See #873 This fixes it by, instead of only considering a join table row a duplicate based solely on its foreign keys, also take into account other columns (in the case of event-question-group, its `EQG_primary` value). This causes the primary question group relation to not get overwritten. **Note**: if you have an event on which you were reproducing #873, just switching to this branch and updating the event **won't** fix it. This just prevents the issue from occurring in the future for newly saved events. (IMO that's ok because this hasn't been released yet, so it's just us EE team who are inconvenienced- had it been released we'd want to retroactively fix those events) ## How has this been tested <!-- Please describe in detail how you tested your changes and how testing can be reproduced --> <!-- Include details of your testing environment, and tests ran to see how your changes affect other areas of code --> <!-- Include any notes about automated tests you've written for this pull request. Pull requests with automated tests are preferred. --> * [ ] 1. Set up an event that requires the Personal Information Group for Additional Attendees 2. Select 2 or more tickets, and submit TS form 3. You'll be redirected to SPCO step 1 4. See missing attendee 1 form ## Checklist * [ ] I have read the documentation relating to systems affected by this pull request, see https://github.com/eventespresso/event-espresso-core/tree/master/docs * [ ] User input is adequately validated and sanitized * [ ] all publicly displayed strings are internationalized (usually using `esc_html__()`, see https://codex.wordpress.org/I18n_for_WordPress_Developers) * [ ] My code is tested. * [ ] My code follows the Event Espresso code style. * [ ] My code has proper inline documentation. * [ ] My code accounts for when the site is in Maintenance Mode (MM2 especially disallows usage of models) "
Problem this Pull Request solves
#790
Adds relation endpoints for simplifying adding and removing relations between individual model objects.
Also, fixes a bug/feature in the models that facilitated multiple entries in join tables having the same foreign keys.
Please see documentation added in this PR for more: https://github.com/eventespresso/event-espresso-core/blob/FET/rest-relation-endpoints/docs/C--REST-API/ee4-rest-api-editing-relations.md
How has this been tested
New features unit tested, so we should just verify there are no regressions by...
Checklist
esc_html__()
, see https://codex.wordpress.org/I18n_for_WordPress_Developers)